﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IHISCETeim.DAL;
using IHISCETeim.Model;
using IHISCETeim.Library;
using System.Data;


namespace IHISCETeim.BLL
{
    public class VIPBuyController
    {
        /// <summary>
        /// 新增VIP采购
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="listDetail"></param>
        /// <param name="isSendEmail">true表示需要发邮件通知配件部,false表示不用.</param>
        /// <returns></returns>
        public static int Add(VIPBuyInfo obj, List<VIPBuyDetailInfo> listDetail,bool isSendEmail)
        {
            int BUYID=VIPBuyDAL.Add(obj, listDetail);
            if (BUYID <= 0)
                return 0;
            if (isSendEmail)
            {
                VIPBuyInfo _temp = GetList(BUYID);
                SEMailListInfo emailObj=  VIPEmailController.GetVIPBuyPassEmail(_temp);
                SEMailListDAL.Add(emailObj);
                return 1;//经销商添加，需要审核
            }
            if (isSendEmail == false)
            {
                obj.BuyId = BUYID;
                VIPBuyDAL.UpdatePass(obj, listDetail);
                return 2;//公司内部人员添加，不用审核
            }
            return 0;
        }


        public static bool Delete(int BuyId)
        {
            return VIPBuyDAL.Delete(BuyId);
        }
        public static List<VIPBuyDetailInfo> GetAllDetail(int BuyId)
        {
            return  CBO.FillCollection<VIPBuyDetailInfo>( VIPBuyDAL.GetAllDetail(BuyId));
        }
        public static VIPBuyInfo GetList(int BuyId)
        {
            return  CBO.FillObject<VIPBuyInfo>(VIPBuyDAL.GetList(BuyId));
        }
        public static DataTable GetPagination(string WhereSql, int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            return VIPBuyDAL.GetPagination(WhereSql, PageIndex, PageSize, Sort, ref  TotalCount);
        }
        /// <summary>
        /// 返回1，表示成功0表示失败
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="listDetail"></param>
        /// <returns></returns>
        public static int UpdatePass(VIPBuyInfo obj, List<VIPBuyDetailInfo> listDetail, bool isSendEmail)
        {
            return VIPBuyDAL.UpdatePass(obj, listDetail);
        }
    }
}
